package thread2;

import jdk.internal.dynalink.beans.StaticClass;
import mytest.Test1;

// 线程的打断
public class Demo8 {
    private static boolean isQuit = false;
    private static final int a = 10;//线程之间共享的资源就是全局的变量

    public  void main(String[] args) throws InterruptedException {
        // boolean isQuit = false;
        /*static*/ int a = 10;

        Thread t = new Thread(() -> {//就近向外选择指定的原则
            while (!isQuit) {
                // 此处的打印可以替换成任意的逻辑来表示线程的实际工作内容
                System.out.println("线程工作中");
                //a = 10;就是常量了
                isQuit = true;//1
//                int b = a + 10;//线程与线程各自里面定义的局部的，就是各自私有的，无法互相访问，除非它是个常量不是私有的即final修饰，即是共用的
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("线程工作完毕!");
        });
        a = 10;//2
        t.start();
        Thread.sleep(5000);
        isQuit = true;
        System.out.println("设置 isQuit 为 true");
    }
}
class test5 {
    int b = 0;
      class test6 {

    }
    void methoud() {
        test5 test1 = new test5();
        test6 test2 = new test5.test6();
        /*test6 test = new */;
        //test.b = 10;
        Thread thread = new Thread(()->{
            this.methoud();
            int a = 10;
            b = 10;
        });
    }

      public static void main(String[] args) {
        int a = 10;
        //test6 test = new test6();
        //test.b = 10;
    }
}

class Test {
    static void methoud1() {
        try {
            throw new InterruptedException();//异常产生直接catch捕捉销毁掉
        }catch (InterruptedException e) {}
    }
    static void methoud2() throws InterruptedException {
        throw new InterruptedException();//异常产生直接终止当前方法并向外抛出
    }
    public static void main(String[] args) {
        methoud1();

        try {
            methoud2();//抛到main方法层时ctach捕捉销毁掉了
        }catch (InterruptedException e) {}
    }
}
